unit frm_AbonentsMeters;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, shbl_Card, ActnList, ComCtrls, ToolWin, StdCtrls, Buttons,
  ExtCtrls, DB, FIBDataSet, pFIBDataSet, FIBDatabase, pFIBDatabase, Mask,
  DBCtrlsEh, DBGridEh, GridsEh, DBLookupEh, PropFilerEh, PropStorageEh;

type
  TfrmAbonentsMeters = class(TshblCard)
    LocalTrans: TpFIBTransaction;
    ds_AbonentsMeters: TpFIBDataSet;
    dsc_AbonentsMeters: TDataSource;
    ds_BuildInfo: TpFIBDataSet;
    dsc_BuildInfo: TDataSource;
    Panel2: TPanel;
    GroupBox1: TGroupBox;
    ds_BuildInfoADDRESS: TFIBStringField;
    ds_Services: TpFIBDataSet;
    dsc_Services: TDataSource;
    GroupBox2: TGroupBox;
    DBEditEh2: TDBEditEh;
    lcbServices: TDBLookupComboboxEh;
    dbg_AbonentsMeters: TDBGridEh;
    ds_ServicesID: TFIBIntegerField;
    ds_ServicesNAME: TFIBStringField;
    ds_AbonentsMetersID: TFIBIntegerField;
    ds_AbonentsMetersADDRESS: TFIBStringField;
    bSearch: TButton;
    ds_AbonentsMetersDOGOVOR_ID: TFIBIntegerField;
    ds_AbonentsMetersLASTCHARGEDATE: TFIBDateField;
    procedure FormShow(Sender: TObject);
    procedure bSearchClick(Sender: TObject);
    procedure dbg_AbonentsMetersDblClick(Sender: TObject);
  private
    { Private declarations }
  public
    pbuilding_id, pabonent_id :integer;

  end;

var
  frmAbonentsMeters: TfrmAbonentsMeters;

function AbonentsMetersDlg (FBuilding_id, FAbonent_id, FGroup_id :integer; aOwner :TComponent): boolean;

implementation

uses uDM, frm_ChargeMeter;

{$R *.dfm}

function AbonentsMetersDlg (FBuilding_id, FAbonent_id, FGroup_id :integer; aOwner :TComponent): boolean;
begin
  result := true;
  frmAbonentsMeters := TfrmAbonentsMeters.Create(aOwner);

  frmAbonentsMeters.pabonent_id := FAbonent_id;
  frmAbonentsMeters.pbuilding_id := FBuilding_id;

  frmAbonentsMeters.ShowModal;

  FreeAndNil (frmAbonentsMeters);
end;

procedure TfrmAbonentsMeters.FormShow(Sender: TObject);
begin
  inherited;
  ds_BuildInfo.ParamByName('pabonent_id').Value := pabonent_id;
  ds_BuildInfo.Open;
  ds_Services.Open;

end;

procedure TfrmAbonentsMeters.bSearchClick(Sender: TObject);
begin
  if lcbServices.KeyValue = null then exit;

  ds_AbonentsMeters.ParamByName('pbuilding_id').Value := pbuilding_id;
  ds_AbonentsMeters.ParamByName('pgroup_id').Value := lcbServices.KeyValue;
  ds_AbonentsMeters.FullRefresh;
end;

procedure TfrmAbonentsMeters.dbg_AbonentsMetersDblClick(Sender: TObject);
begin
  if ds_AbonentsMeters.RecordCount = 0 then exit;
  if ds_AbonentsMetersDOGOVOR_ID.IsNull then exit;

  ChargeMeterDlg (ds_AbonentsMetersDOGOVOR_ID.Value, 0, Self);
  ds_AbonentsMeters.Refresh;
end;

end.
